package com.bm.util;

import java.sql.Connection;

import com.alibaba.druid.pool.DruidDataSource;

public class ConnectionFactory {
	 private static DruidDataSource dataSource=null;
	 
	  static {
	        try {
	        	Config config= Config.getConfig();
	            dataSource = new DruidDataSource();
	            dataSource.setDriverClassName(config.getDrive());
	            dataSource.setUrl(config.getUrl());
	            dataSource.setUsername(config.getUser());
	            dataSource.setPassword(config.getPassword());
	            dataSource.setInitialSize(config.getInitialSize());
	            dataSource.setMinIdle(config.getMinIdle());
	            dataSource.setMaxActive(config.getMaxActive());
	            dataSource.setPoolPreparedStatements(false);
	            

	        } catch (Exception e) {
	            e.printStackTrace();
	        }
	    }
	  
	  public static synchronized Connection getConnection() {
	        Connection conn = null;
	        try {
	            conn = dataSource.getConnection();
	        } catch (Exception e) {
	            e.printStackTrace();
	        }
	        return conn;
	    }
	  
}
